package com.chen.service.impl;

import com.chen.dao.ArticleMapper;
import com.chen.pojo.Article;
import com.chen.pojo.ArticleType;
import com.chen.pojo.User;
import com.chen.service.ArticleService;
import com.chen.utils.MarkDownUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.javassist.NotFoundException;
import org.springframework.beans.BeanUtils;


import java.util.List;

public class ArticleServiceImpl implements ArticleService {
    //组合mapper
    private ArticleMapper articleMapper;

    public void setArticleMapper(ArticleMapper articleMapper) {
        this.articleMapper = articleMapper;
    }

    public List<ArticleType> allBlog(int pageNum, int pageSize) {
        //先开始分页
        PageHelper.startPage(pageNum,pageSize);
        //查询所有列表
        List<ArticleType> articles = articleMapper.allBlog();
        //查询完毕后分页
        PageInfo<ArticleType> pageInfo = new PageInfo<>(articles);
        //返回分页后的列表
        return pageInfo.getList();
    }

    public int addBlog(Article article) {
        return articleMapper.addBlog(article);
    }

    //根据类型查找博客信息
    @Override
    public List<ArticleType> getByType(int pageNum, int pageSize,Integer type_id) {
        //先开始分页
        PageHelper.startPage(pageNum,pageSize);
        //查询所有列表
        List<ArticleType> articles = articleMapper.getByType(type_id);
        //查询完毕后分页
        PageInfo<ArticleType> pageInfo = new PageInfo<>(articles);
        //返回分页后的列表
        return pageInfo.getList();
    }

    @Override
    public List<Article> getRecent() {
        return articleMapper.getRecent();
    }

    //根据博客id获取博客详情信息
    @Override
    public Article getArticleDetail(Integer article_id) {


        return articleMapper.getArticleDetail(article_id);
    }

    @Override
    public int addZan(int article_id) {
        return articleMapper.addZan(article_id);
    }

    @Override
    public int addRead(int article_id) {
        return articleMapper.addRead(article_id);
    }
}
